package com.keste.model.pmo.am;

import com.keste.model.pmo.am.common.ProjectManagementAM;

import com.keste.model.pmo.view.TaskTransientVOImpl;

import java.util.Map;

import oracle.adf.share.ADFContext;

import oracle.jbo.VariableValueManager;
import oracle.jbo.ViewCriteria;
import oracle.jbo.ViewCriteriaManager;
import oracle.jbo.domain.Number;
import oracle.jbo.server.ApplicationModuleImpl;
import oracle.jbo.server.ViewLinkImpl;
import oracle.jbo.server.ViewObjectImpl;
// ---------------------------------------------------------------------
// ---    File generated by Oracle ADF Business Components Design Time.
// ---    Wed Nov 12 17:35:08 IST 2014
// ---    Custom code may be added to this class.
// ---    Warning: Do not modify method signatures of generated methods.
// ---------------------------------------------------------------------
public class ProjectManagementAMImpl extends ApplicationModuleImpl implements ProjectManagementAM {
    /**
     * This is the default constructor (do not remove).
     */
    public ProjectManagementAMImpl() {
    }

    /**
     * Container's getter for ProjectDetails.
     * @return ProjectDetails
     */
    public ViewObjectImpl getProjectDetails() {
        return (ViewObjectImpl)findViewObject("ProjectDetails");
    }

    /**
     * Container's getter for TaskDetails.
     * @return TaskDetails
     */
    public ViewObjectImpl getTaskDetails() {
        return (ViewObjectImpl)findViewObject("TaskDetails");
    }

    /**
     * Container's getter for TaskTransient.
     * @return TaskTransient
     */
    public TaskTransientVOImpl getTaskTransient() {
        return (TaskTransientVOImpl)findViewObject("TaskTransient");
    }

    public void emptyTable() {
        ViewObjectImpl vo = this.getTaskDetailsVO();
        vo.executeEmptyRowSet();
    }

    public void searchTask(String taskName, String taskStatus) {
        ViewObjectImpl taskDetailsVO = this.getTaskDetailsVO();
        ViewCriteria taskNameVC =
            taskDetailsVO.getViewCriteria("taskNameCriteria");
        ViewCriteria taskStatusVC =
            taskDetailsVO.getViewCriteria("taskStatusCriteria");

        if (taskName != null) {
            taskDetailsVO.setNamedWhereClauseParam("bindTaskName", taskName);
            taskNameVC.resetCriteria();
            taskDetailsVO.applyViewCriteria(taskNameVC, true);
        }

        if (taskStatus != null) {
            taskDetailsVO.setNamedWhereClauseParam("bindTaskStatus",
                                                   taskStatus);
            taskStatusVC.resetCriteria();
            taskDetailsVO.applyViewCriteria(taskStatusVC, true);
        }
        taskDetailsVO.executeQuery();
    }

    /**
     * Container's getter for TaskEmployeeMap.
     * @return TaskEmployeeMap
     */
    public ViewObjectImpl getTaskEmployeeMap() {
        return (ViewObjectImpl)findViewObject("TaskEmployeeMap");
    }

    public void filterEmployees() {
        Map pageFlowScope = ADFContext.getCurrent().getPageFlowScope();
        ViewObjectImpl taskEmployeeMapVO = this.getTaskEmployeeMap();
        Number taskId = (Number)pageFlowScope.get("taskId");
        taskEmployeeMapVO.setWhereClause("TaskEmployeeMapEO.TASK_ID =" +
                                         taskId);
        taskEmployeeMapVO.executeQuery();
    }

    public void emptyProjectTable() {
        ViewObjectImpl projectDetails = this.getProjectDetails();
        projectDetails.executeEmptyRowSet();
    }

    public void filterProjects(String Name, String Status) {
        ViewObjectImpl projectDetailsViewImpl = this.getProjectDetails();
        ViewCriteriaManager vcm =
            projectDetailsViewImpl.getViewCriteriaManager();
        projectDetailsViewImpl.executeEmptyRowSet();
        if (Name != null) {

            ViewCriteria namedVC = vcm.getViewCriteria("ProjectNameCriteria");
            VariableValueManager vvm = namedVC.ensureVariableManager();
            vvm.setVariableValue("bProjectName", Name);
            projectDetailsViewImpl.applyViewCriteria(namedVC, true);

        }
        if (Status != null) {
            ViewCriteria statusVC =
                vcm.getViewCriteria("ProjectStatusCriteria");
            VariableValueManager vvm = statusVC.ensureVariableManager();
            vvm.setVariableValue("bProjectStatus", Status);
            projectDetailsViewImpl.applyViewCriteria(statusVC, true);

        }
        projectDetailsViewImpl.executeQuery();
        System.out.println("Query  :" + projectDetailsViewImpl.getQuery());
        System.out.println("Project row count" +
                           projectDetailsViewImpl.getEstimatedRowCount());
    }


    /**
     * Container's getter for TaskDetailsVO.
     * @return TaskDetailsVO
     */
    public ViewObjectImpl getTaskDetailsVO() {
        return (ViewObjectImpl)findViewObject("TaskDetailsVO");
    }

    /**
     * Container's getter for ProjectDetailsToTaskDetailsVL1.
     * @return ProjectDetailsToTaskDetailsVL1
     */
    public ViewLinkImpl getProjectDetailsToTaskDetailsVL1() {
        return (ViewLinkImpl)findViewLink("ProjectDetailsToTaskDetailsVL1");
    }

    /**
     * Container's getter for ProjectDetailsTransient1.
     * @return ProjectDetailsTransient1
     */
    public ViewObjectImpl getProjectDetailsTransient() {
        return (ViewObjectImpl)findViewObject("ProjectDetailsTransient");
    }

    /**
     * Container's getter for TaskEmployeeMapVO.
     * @return TaskEmployeeMapVO
     */
    public ViewObjectImpl getTaskEmployeeMapVO() {
        return (ViewObjectImpl)findViewObject("TaskEmployeeMapVO");
    }

    /**
     * Container's getter for TaskDetailsToTaskEmployeeMapVL.
     * @return TaskDetailsToTaskEmployeeMapVL
     */
    public ViewLinkImpl getTaskDetailsToTaskEmployeeMapVL() {
        return (ViewLinkImpl)findViewLink("TaskDetailsToTaskEmployeeMapVL");
    }
}
